#ifndef LOADERWIZARDPAGE_H
#define LOADERWIZARDPAGE_H

#include <QtGui/QWizardPage>
//#include <asynchronousworker.h>
#include <asynchronousworker.cpp>
#include <correlationmatrix.h>
#include <anatomicaltemplate.h>
#include <functionalnetwork.h>
#include <QMutex>
#include <QFile>
#include <QtGui/QMessageBox>
#include <QDir>

namespace Ui {
    class LoaderWizardPage;
}

class LoaderWizardPage : public QWizardPage {
    Q_OBJECT
    Q_DISABLE_COPY(LoaderWizardPage)

private slots:
    void onProgress(int value, int max);
    void onsubTaskFinished(int subTask);

signals:
    void subTaskFinished(int subTask);

public:
    explicit LoaderWizardPage(QWidget *parent = 0);
    virtual ~LoaderWizardPage();

    void LoadMatrix();
    void LoadTemplateNames();
    void LoadTemplate3DMask();
    void LoadNetworkLinks();

    void setIndividualsMatrixFile(QString file);
	void setMeanMatrixFile(QString file);
	void setMedianMatrixFile(QString file);

    QVector<CorrelationMatrix*>& GetIndividualsMatrices() const;
	CorrelationMatrix* GetMedianMatrix();
	CorrelationMatrix* GetMeanMatrix();

    AnatomicalTemplate* GetTemplate();
    FunctionalNetwork* GetNetwork();

protected:
    virtual void changeEvent(QEvent *e);
    virtual void initializePage();
    virtual bool isComplete () const;

private:
    void StartAsyncLoad(int subTask);

	void calculateMean();
	void calculateMedian();
	void loadMean();
	void loadMedian();

	bool finished;

    Ui::LoaderWizardPage *m_ui;
    AsynchronousWorker<LoaderWizardPage> worker;
    QVector<CorrelationMatrix*> matrices;
	CorrelationMatrix* meanMatrix;
	CorrelationMatrix* medianMatrix;
    AnatomicalTemplate aaltemplate;
    FunctionalNetwork network;

    QString indivFile;
	QString meanFile;
	QString medianFile;
    QMutex mutex;

};
//template class AsynchronousWorker<LoaderWizardPage>;

#endif // LOADERWIZARDPAGE_H
